package com.mxdx.edu.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.mxdx.edu.dao.LearningExperienceInfoDao;
import com.mxdx.edu.model.LearningExperienceInfo;
import com.mxdx.edu.service.ILearningExperienceInfoService;

@Service
public class LearningExperienceInfoService implements
		ILearningExperienceInfoService {

	@Resource
	private LearningExperienceInfoDao learningExperienceInfoDao;

	@Override
	public boolean save(LearningExperienceInfo learningExperienceInfo) {
		return learningExperienceInfoDao.save(learningExperienceInfo) > 0;
	}

	@Override
	public List<LearningExperienceInfo> selectLearningExperienceInfo(
			Map<String, Object> map) {
		List<Map<String, Object>> listMap = learningExperienceInfoDao
				.findListByMap(map);
		List<LearningExperienceInfo> list = new ArrayList<>();
		for (Map<String, Object> temp : listMap) {
			JSONObject json = (JSONObject) JSONObject.toJSON(temp);
			list.add(JSONObject
					.toJavaObject(json, LearningExperienceInfo.class));
		}
		return list;
	}

	@Override
	public boolean mergeLearningExperienceInfo(Map<String, Object> map) {
		return learningExperienceInfoDao.updateByMap(map) > 0;
	}

	@Override
	public List<Map<String, Object>> findLearningExperienceInfo(
			Map<String, Object> map) {
		return learningExperienceInfoDao.findListByMap(map);
	}
}
